/**
 *@auther: tang
 *@Date: 2021-01-29
 *Project: p2pPlatformSys
 *Lang: TypeScript
 */
import { Service } from 'egg';
class FileService extends Service {
  async saveFilePath(filePath:string) {
    const { app } = this;
    const res = await app.mysql.insert('upload', {
      path: filePath,
    }).catch(() => {
      return {
        code: 400,
        msg: '数据库异常',
        path: null,
      };
    });
    if (res) {
      return {
        code: 200,
        msg: '保存成功',
        path: ((filePath.replace(/\\/g, '/')).split('/').slice(2))
          .join('/'),
      };
    }
  }

}

module.exports = FileService;
